package com.hubu.blog.entity.table;

import com.mybatisflex.core.query.QueryColumn;
import com.mybatisflex.core.table.TableDef;

import java.io.Serial;

/**
 * 系统权限表(支持嵌套结构) 表定义层。
 *
 * @author 331126135@qq.com
 * @since 2025-06-10
 */
public class PermissionTableDef extends TableDef {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 系统权限表(支持嵌套结构)
     */
    public static final PermissionTableDef PERMISSION = new PermissionTableDef();

    /**
     * 权限ID，雪花算法生成
     */
    public final QueryColumn ID = new QueryColumn(this, "id");

    /**
     * 权限层级(1开始)
     */
    public final QueryColumn LEVEL = new QueryColumn(this, "level");

    /**
     * 状态
     */
    public final QueryColumn STATUS = new QueryColumn(this, "status");

    /**
     * 父权限ID(构建权限树)
     */
    public final QueryColumn PARENT_ID = new QueryColumn(this, "parent_id");

    /**
     * 权限代码(如system:user:add)
     */
    public final QueryColumn PERM_CODE = new QueryColumn(this, "perm_code");

    /**
     * 权限名称(如添加用户)
     */
    public final QueryColumn PERM_NAME = new QueryColumn(this, "perm_name");

    /**
     * 是否删除
     */
    public final QueryColumn IS_DELETED = new QueryColumn(this, "is_deleted");

    /**
     * 创建时间
     */
    public final QueryColumn CREATE_TIME = new QueryColumn(this, "create_time");

    /**
     * 删除时间
     */
    public final QueryColumn DELETE_TIME = new QueryColumn(this, "delete_time");

    /**
     * 系统标识
     */
    public final QueryColumn SYSTEM_FLAG = new QueryColumn(this, "system_flag");

    /**
     * 更新时间
     */
    public final QueryColumn UPDATE_TIME = new QueryColumn(this, "update_time");

    /**
     * 权限描述
     */
    public final QueryColumn DESCRIPTION = new QueryColumn(this, "description");

    /**
     * 所有字段。
     */
    public final QueryColumn ALL_COLUMNS = new QueryColumn(this, "*");

    /**
     * 默认字段，不包含逻辑删除或者 large 等字段。
     */
    public final QueryColumn[] DEFAULT_COLUMNS = new QueryColumn[]{ID, PERM_CODE, PERM_NAME, DESCRIPTION, PARENT_ID, LEVEL, STATUS, SYSTEM_FLAG, CREATE_TIME, UPDATE_TIME, DELETE_TIME};

    public PermissionTableDef() {
        super("db_blog", "blog_permission");
    }

    private PermissionTableDef(String schema, String name, String alisa) {
        super(schema, name, alisa);
    }

    public PermissionTableDef as(String alias) {
        String key = getNameWithSchema() + "." + alias;
        return getCache(key, k -> new PermissionTableDef("db_blog", "blog_permission", alias));
    }

}
